package com.dao;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.beans.UserInfo;
@Service
public class UserDao {
	private static Map<Integer, UserInfo> usreMap = null;

	static {
		usreMap = new HashMap<Integer, UserInfo>();
		usreMap.put(1001, new UserInfo(1001, "陈聪", "1234567891@163.com", "java软件工程师",0,new Date()));
		usreMap.put(1002, new UserInfo(1002, "范鸽", "1234567892@163.com", " C#硬件工程师",0,new Date()));
		usreMap.put(1003, new UserInfo(1003, "谭冰倩", "1234567893@163.com", "Python工程师",0, new Date()));
		usreMap.put(1004, new UserInfo(1004, "赵治硕", "1234567894@163.com", "计算工中心工程师",1,new Date()));
		usreMap.put(1005, new UserInfo(1005, "矫咪", "1234567895@163.com", "林大毕业生",1,new Date()));
	}
	private static Integer initId = 1006;
	/**
	 * 添加和修改调用同一个方法
	 * @param user
	 */
	public void save(UserInfo user) {
		if (user.getId() == null) {
			user.setId(initId++);
		}
		usreMap.put(user.getId(), user);
	}

	public Collection<UserInfo> getUserList() {
		return usreMap.values();
	}

	public UserInfo getUserById(Integer id) {
		return usreMap.get(id);
	}

	public void deleteUserById(Integer id) {
		usreMap.remove(id);
	}
}
